﻿using System.Drawing;
using System.Web;
using DevExpress.Web.ASPxSpreadsheet;
using TheHeGeo.Util;
using TheHeGeo.Util.Validate;

namespace TheHeGeo.Tools.TemplateExcel
{
    public class QuTemplate:SpreadSheetTemplate
    {
        public QuTemplate()
        {
            Type = SpreadSheetTemplateType.QuTemplate;
            Name = "QuTemplate";
            FilePath = HttpRuntime.AppDomainAppPath + "Tools\\TemplateFile\\QuTemplate.xlsx";
        }
        protected override void CustomGenTemplate(ASPxSpreadsheet sheet,ASPxSpreadsheet tempsheet)
        {
            tempsheet.Open(FilePath);
            sheet.Document.Worksheets.ActiveWorksheet = sheet.Document.Worksheets[tempsheet.Document.Worksheets.ActiveWorksheet.Name];
            sheet.Document.Worksheets.ActiveWorksheet.CopyFrom(tempsheet.Document.Worksheets.ActiveWorksheet);
            tempsheet.Close();
           
        }

        protected override void AddValidateByFontColor()
        {
            FontColorValidateDict.Add(Color.FromArgb(221, 221, 221), new ObjValidateDoubleGreater("Phải là số thực >= 0", 0, true));
        }

        protected override void AddInputRange(ASPxSpreadsheet sheet)
        {
            //InputRangeDict.Add("InputArea1", new ObjInputRowRange("InputArea1", "Sheet1", 6, 7, sheet.Document.Worksheets["Sheet1"].Columns["C"].Index, sheet.Document.Worksheets["Sheet1"].Columns["C"].Index, false));
            //InputRangeDict.Add("InputArea2", new ObjInputRowRange("InputArea2", "Sheet1", 6, 8, sheet.Document.Worksheets["Sheet1"].Columns["I"].Index, sheet.Document.Worksheets["Sheet1"].Columns["I"].Index, false));
            //InputRangeDict.Add("InputArea3", new ObjInputRowRange("InputArea3", "Sheet1", 10, 15, sheet.Document.Worksheets["Sheet1"].Columns["G"].Index, sheet.Document.Worksheets["Sheet1"].Columns["H"].Index, false));
           // InputRangeDict.Add("InputArea4", new ObjInputRowRange("InputArea4", "Sheet1", 20, 50, sheet.Document.Worksheets["Sheet1"].Columns["D"].Index, sheet.Document.Worksheets["Sheet1"].Columns["D"].Index, false));
            
           }


        protected void SetReadOnly(ASPxSpreadsheet sheet)
        {
            int ColumnStart = 0;
            int ColumnEnd = 12;
            int RowCountStart = 0;
            int RowCountEnd = 58;
            for(RowCountStart =0; RowCountStart <=RowCountEnd; RowCountStart++ )
                for (ColumnStart = 0; ColumnStart <= ColumnEnd; ColumnStart++)
                {
                    sheet.Document.Worksheets["Sheet1"].Rows[RowCountStart][ColumnStart].Protection.Locked = true;
                }
        }

        protected override void CalculateSheet(ASPxSpreadsheet sheet)
        {
           
        }

    }
}